package forward.Module.Modules.Move;

import forward.api.EventHandler;
import forward.api.Events.World.EventMove;
import forward.Manager.ModuleManager;
import forward.Module.Module;
import forward.Module.ModuleType;
import forward.Util.BlockUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.potion.Potion;
import net.minecraft.util.MovementInput;

public class Strafe extends Module {
	public Strafe() {
		super("Strafe", new String[] { "Strafe" }, ModuleType.Move);
		// super("PacketMotior", new String[]{"PacketMotior"}, ModuleType.Misc);
	}

	/*
	 * public static void SmartMove(EventMove event) { double speed = 0.0; double
	 * moveSpeed = Math.max(getBaseMoveSpeed(), speed); MovementInput var10000 =
	 * Minecraft.thePlayer.movementInput; float forward = MovementInput.moveForward;
	 * var10000 = Minecraft.thePlayer.movementInput; float strafe =
	 * MovementInput.moveStrafe; float yaw = Minecraft.thePlayer.rotationYaw; if
	 * (forward == 0.0F && strafe == 0.0F) { event.x = 0.0D; event.z = 0.0D; } else
	 * if (forward != 0.0F) { if (strafe >= 1.0F) { yaw += (float)(forward > 0.0F ?
	 * -45 : 45); strafe = 0.0F; } else if (strafe <= -1.0F) { yaw +=
	 * (float)(forward > 0.0F ? 45 : -45); strafe = 0.0F; }
	 *
	 * if (forward > 0.0F) { forward = 1.0F; } else if (forward < 0.0F) { forward =
	 * -1.0F; } }
	 *
	 * double mx = Math.cos(Math.toRadians((double)(yaw + 90.0F))); double mz =
	 * Math.sin(Math.toRadians((double)(yaw + 90.0F))); event.x = (double)forward *
	 * moveSpeed * mx + (double)strafe * moveSpeed * mz; event.z = (double)forward *
	 * moveSpeed * mz - (double)strafe * moveSpeed * mx;
	 * Minecraft.thePlayer.stepHeight = 0.6F; if (forward == 0.0F && strafe == 0.0F)
	 * { event.x = 0.0D; event.z = 0.0D; }
	 *
	 * }
	 */
	public static double getBaseMoveSpeed() {
		double baseSpeed;
		if (BlockUtils.isInLiquid()) {
			baseSpeed = 0.1D;
		} else {
			baseSpeed = 0.2873D;
		}

		if (Minecraft.thePlayer.isPotionActive(Potion.moveSpeed)) {
			int amplifier = Minecraft.thePlayer.getActivePotionEffect(Potion.moveSpeed).getAmplifier();
			baseSpeed *= 1.0D + 0.2D * (double) (amplifier + 1);
		}

		return baseSpeed;
	}

	public void onEnable() {
		super.onEnable();
	}

	public void onDisable() {
		super.onDisable();
	}

	@EventHandler
	private void onMove(EventMove event) {
		  if (!ModuleManager.getModuleByClass(Speed.class).isEnabled()) {
			double moveSpeed = Math.max(getBaseMoveSpeed(), getBaseMoveSpeed());
			MovementInput var10000 = Minecraft.thePlayer.movementInput;
			float forward = MovementInput.moveForward;
			var10000 = Minecraft.thePlayer.movementInput;
			float strafe = MovementInput.moveStrafe;
			float yaw = Minecraft.thePlayer.rotationYaw;
			if (forward == 0.0F && strafe == 0.0F) {
				event.x = 0.0D;
				event.z = 0.0D;
			} else if (forward != 0.0F) {
				if (strafe >= 1.0F) {
					yaw += (float) (forward > 0.0F ? -45 : 45);
					strafe = 0.0F;
				} else if (strafe <= -1.0F) {
					yaw += (float) (forward > 0.0F ? 45 : -45);
					strafe = 0.0F;
				}

				if (forward > 0.0F) {
					forward = 1.0F;
				} else if (forward < 0.0F) {
					forward = -1.0F;
				}
			}

			double mx = Math.cos(Math.toRadians((double) (yaw + 90.0F)));
			double mz = Math.sin(Math.toRadians((double) (yaw + 90.0F)));
			event.x = (double) forward * moveSpeed * mx + (double) strafe * moveSpeed * mz;
			event.z = (double) forward * moveSpeed * mz - (double) strafe * moveSpeed * mx;
			Minecraft.thePlayer.stepHeight = 0.6F;
			if (forward == 0.0F && strafe == 0.0F) {
				event.x = 0.0D;
				event.z = 0.0D;
			}

		}
	}
}
